import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

class onCaseColumns extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        type: 'checkbox',
        width: 40,
        align: 'center'
      },
      {
        title: '序号',
        type: 'index',
        width: 70,
        align: 'center'
      },
      {
        title: '姓名',
        field: 'userName',
        minWidth: 140
      },
      {
        title: '工号 ',
        field: 'workNo',
        minWidth: 120
      },
      {
        title: '手机号',
        field: 'phone',
        minWidth: 150
      },
      {
        title: '角色',
        field: 'roleNames',
        minWidth: 180,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.roleNames
                ? params.row.roleNames.length > 0
                  ? params.row.roleNames.join(',')
                  : '-'
                : '-'
            })
          }
        }
      },
      {
        title: '所属组别',
        field: 'groupName',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.groupName ? params.row.groupName : '无'
            })
          }
        }
      },
      {
        title: '状态',
        field: 'buildingType',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.buildingType ? (params.row.buildingType == 1 ? '在案' : '调离中') : '-'
            })
          }
        }
      },
      {
        title: '分摊比例（%）',
        field: 'amortizationRatio',
        minWidth: 140
      },
      {
        title: '是否组长',
        field: 'groupLeader',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.groupLeader ? (params.row.groupLeader == 1 ? '是' : '否') : '否'
            })
          }
        }
      },
      {
        title: '是否在编',
        field: 'compile',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.compile ? (params.row.compile == 1 ? '是' : '否') : '-'
            })
          }
        }
      },
      {
        title: '进场日期',
        field: 'factoryDate',
        minWidth: 120,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.factoryDate ? _this.$tool.formatterDate(params.row.factoryDate) : '-'
            })
          }
        }
      },
      {
        title: '操作',
        field: 'operation',
        width: 200,
        align: 'center',
        fixed: 'right',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: '查看',
              event: 'checkUser',
              data: params.row
            })
            btns.push({
              title: _this.unlocking('0102030400') ? '变更' : '',
              event: 'changeUser',
              data: params.row
            })
            if (params.row.compile == 1) {
              btns.push({
                title: _this.unlocking('0102030500') ? '调出' : '',
                event: 'delUserFun',
                data: params.row
              })
            } else {
              btns.push({
                title: _this.unlocking('0102030900') ? '关闭权限' : '',
                event: 'closePower',
                data: params.row
              })
            }
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default onCaseColumns
